package com.yh.ssm.test;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.yh.ssm.controller.ProductAction;
import com.yh.ssm.model.Product;
import com.yh.ssm.service.IProductService;
import com.yh.ssm.service.impl.ProductServiceImpl;

@RunWith(SpringJUnit4ClassRunner.class)
//配置了@ContextConfiguration注解并使用该注解的locations属性指明spring和配置文件之后，
@ContextConfiguration(locations = {"classpath:spring/spring.xml", "classpath:spring/spring-mybatis.xml","classpath:aop.xml" })
public class Ptest {
	   private static Logger logger = LogManager.getLogger(Ptest.class);
	@Autowired
	private IProductService ips;
	/*
	@Test
	public void add(){
		
		Product pd=new Product();
		
		pd.setName("tt");
		pd.setPrice(100.0);
		pd.setPath("../load/7.jpg");
		pd.setDescription("asfd");
		ips.save(pd);
	}*/
	@Test
	public void find(){
	/*	ApplicationContext ctx = new AnnotationConfigApplicationContext("aop.xml");*/
		/*ProductServiceImpl userService = ctx.getBean("ips", ProductServiceImpl.class);*/
		Product pd=new Product();
		pd.setId(10);
		Product pd1=new Product();
		pd1=ips.find(pd);
		logger.info(pd1.getName());
	}
	/*@Test
	public void edit(){
		Product pd=new Product();
		pd.setId(1);
		pd.setName("灰色df");
		int i=ips.edit(pd);
		if(i>0){
			logger.info("修改成功");
		}
	}
	@Test
	public  void del(){
		Product pd=new Product();
		pd.setId(1);
		int i=ips.del(pd);
		if(i>0){
			logger.info("删除成功");
		}
	}*/
}
